﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace JasLib.Interop.Win32
{
    public static class DWMAPI
    {
        [DllImport(Constants.ModuleNames.DWMAPI, PreserveSig = false)]
        public static extern void DwmEnableBlurBehindWindow(HWND hwnd, ref DWM_BLURBEHIND blurBehind);

        [DllImport(Constants.ModuleNames.DWMAPI, PreserveSig = false)]
        public static extern HRESULT DwmExtendFrameIntoClientArea([In] HWND hWindow, [In] ref MARGINS pMarInset);

        [DllImport(Constants.ModuleNames.DWMAPI, PreserveSig = false)]
        public static extern HRESULT DwmGetColorizationColor(out uint ColorizationColor, [MarshalAs(UnmanagedType.Bool)]out bool ColorizationOpaqueBlend);

        [DllImport(Constants.ModuleNames.DWMAPI, PreserveSig = false)]
        public static extern HRESULT DwmIsCompositionEnabled([Out] out bool pfEnabled);

        [DllImport(Constants.ModuleNames.DWMAPI, EntryPoint = "#104")]
        public static extern int DwmSetColorizationColor(uint ColorizationColor, bool ColorizationOpaqueBlend, uint Opacity);

        /// <summary>
        /// From the book "Windows Presentation Foundation Unleashed".
        /// </summary>
        /// <param name="window"></param>
        /// <param name="margin"></param>
        /// <returns></returns>
        /*public static bool ExtendGlassFrame(this Window ThisWindow, Thickness ThisMargin)
        {
            if (!DwmIsCompositionEnabled())
                return false;

            IntPtr hwnd = new WindowInteropHelper(ThisWindow).Handle;
            if (hwnd == IntPtr.Zero)
                throw new InvalidOperationException("The Window must be shown before extending glass.");

            /// Set the background to transparent from both the WPF and Win32 perspectives.
            ThisWindow.Background = Brushes.Transparent;
            HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;

            MARGINS margins = new MARGINS(ThisMargin);
            DwmExtendFrameIntoClientArea(hwnd, ref margins);
            return true;
        }*/
    }
}